//
//  Main.swift
//  foundationDemo
//
//  Created by Zhao Mingzhi on 16/6/28.
//  Copyright © 2016年 HNA. All rights reserved.
//
import Foundation
import UIKit
class MainTableController:UITableViewController{
    var dataTable:UITableView!;
    var itemString=["基础控件的使用","静态表格","单击手势","时间选择器的使用","普通选择器的使用","滚动视图"]
    
    var screenObject=UIScreen.mainScreen().bounds;

    override func viewDidLoad() {
        super.viewDidLoad();
        initView();
    }

    func initView(){
        self.title="Demo";
        creatTable();
    }

    func creatTable(){
        let dataTableW:CGFloat=screenObject.width;
        let dataTableH:CGFloat=screenObject.height;
        let dataTableX:CGFloat=0;
        let dataTableY:CGFloat=0;

        dataTable=UITableView(frame: CGRectMake(dataTableX, dataTableY, dataTableW, dataTableH),style:UITableViewStyle.Grouped);
        dataTable.delegate=self;
        dataTable.dataSource=self;
        
        self.view.addSubview(dataTable);
    }
    

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1;
    }
    

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 6;
        
    }

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
            return 50;
    }
    
    override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0;
    }
    
    override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 1;
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let identifier="identtifier";
        var cell=tableView.dequeueReusableCellWithIdentifier(identifier);
        if(cell == nil){
            cell=UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: identifier);
        }
        
        
        cell?.textLabel?.text=itemString[indexPath.row];
        
        cell?.accessoryType=UITableViewCellAccessoryType.DisclosureIndicator;
        return cell!;
    }
    //1.7 表格点击事件
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            //取消选中的样式
            tableView.deselectRowAtIndexPath(indexPath, animated: true);
            //获取点击的行索引
            if(indexPath.row == 0){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("main")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
            }else if(indexPath.row == 1){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "tableStoryboard", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("login")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
            }else if(indexPath.row == 2){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "Recognizer", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("Recognizer")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
            }else if(indexPath.row == 3){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "Popup", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("PopupController")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
            }else if(indexPath.row == 4){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "PickerView", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("PickerView")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
            }else if(indexPath.row == 5){
                let secondStroyBoard:UIStoryboard = UIStoryboard.init(name: "ScrollView", bundle: nil)
                let test2obj:UIViewController = secondStroyBoard.instantiateViewControllerWithIdentifier("ScrollView")
                test2obj.hidesBottomBarWhenPushed=false;//隐藏导航栏
                self.navigationController?.pushViewController(test2obj, animated: true);
        }

    }
    //内存警告
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning();
        print("个人信息内存警告");
    }

}